<?php
include 'dbconnection.php';
//$lat = 26.930628;
//$lon = -82.051262;

$lat=$_GET['lat'];
$lon=$_GET['lng'];

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

/*// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}*/

// Select all the rows in the markers table
//$query = "SELECT * FROM Sign_Posts WHERE `sp_catalog_item_yesno` = '2' limit 10";
$query="SELECT sp_id,sp_latitude,sp_longitude, ( 6371 * acos( cos( radians( $lat ) ) * cos( radians( sp_latitude ) ) * cos( radians( sp_longitude ) - radians( $lon ) ) + sin( radians( $lat ) ) * sin( radians( sp_latitude ) ) ) ) AS distance, sp_latitude, sp_longitude FROM Sign_Posts HAVING distance <1 ORDER BY distance";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['sp_id']) . '" ';
  echo 'address="' . 'address' . '" ';
  echo 'lat="' . $row['sp_latitude'] . '" ';
  echo 'lng="' . $row['sp_longitude'] . '" ';
  echo 'type="' . 'bar' . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';


?>